﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Write.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ImageController : ControllerBase
    {
        private readonly IMediator mediator;

        public ImageController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<dynamic> UploadImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/Imgs/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                //  return mediator.Send("http://localhost:5004/Imgs/" + file.FileName);
                return Ok("http://localhost:5004/Imgs/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
